<?php

class BatchController extends FrontController
{
	public function actionIndex()
	{

        $criteria=new CDbCriteria();
        $criteria->compare('type','BizUser',true);
        $criteria->compare('status','<>active');
        $criteria->addCondition('latitude is NULL');
        $users=Users::model()->findAll($criteria);
        $recordUpdated=0;
        $recordUnUpdated=0;
        $arrUnUpdated=array();
        $varLntArr=array();
        foreach($users as $model){
            if($recordUnUpdated ==500) break;
//            if(trim($model->latitude)==''){
                    if($model->postal_code!=''){
                        $varLnt=getLnt($model->postal_code);
                        array_push($varLntArr,$varLnt);
                        if($varLnt!=null){
                            $model->latitude=$varLnt['lat'];
                            $model->longitude=$varLnt['lng'];
                            $model->update(array('latitude','longitude'));
                            $recordUpdated++;
//                            Users::model()->updateByPk(array('latitude'=>$varLnt['lat'],
//                                'longitude'=>$varLnt['lng'],));
                        }
                        else {

                            $recordUnUpdated++;
                            array_push($arrUnUpdated,array(
                                'postal_code'=>$model->postal_code,
                                'id'=>$model->id
                            ));
                        }

                    }
//            }
        }
        echo "{$recordUpdated} record(s) have been updated.<br> These records are not updated: <br>";
        CVarDumper::dump($arrUnUpdated,10,true);
        Yii::app()->end();
		//$this->render('index');
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}